/*
 * 컴파일을 위해 올려 놓은 소스 입니다.
 * 서버에 반영하지 마시고 다른국가에 적용할 경우 서버에 있는 class 를 카피해서 사용하십시오.
 * 
 */
/**
 * 컴파일을 위해 올려 놓은 소스 입니다.
 * 서버에 반영하지 마시고 다른국가에 적용할 경우 서버에 있는 class 를 카피해서 사용하십시오.
 * 
 */
/*
 * Created on 2004. 9. 27.
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package com.pushmsg.OmaOtaConf.OmaOtaObject;

/**
 * @author dgchun
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class SMTP extends APPLICATION
{
	String EMAIL_addr = null;
	String SMTP_addr = null;
	String SMTP_port = null;
	String SMTP_auth = null;
	String SMTP_id = null;
	String SMTP_pwd = null;	
	String provider_id = null;
	String security = null;
	
	public SMTP(String napid)
	{
//		System.out.println("napid=" + napid);
		super.appid = "25";
		super.napid = napid;
	}
	
	public void setEmailAddr(String addr)
	{
		EMAIL_addr = addr;
	}
	
	public void setSmtpAddr(String addr)
	{
		SMTP_addr = addr;
	}
	
	public void setSmtpPort(String port)
	{
		SMTP_port = port;
	}
	
	public void setSmtpAuth(String auth)
	{
		SMTP_auth = auth;
	}
		
	public void setSmtpId(String id)
	{
		SMTP_id = id;
	}
	
	public void setSmtpPwd(String pwd)
	{
		SMTP_pwd = pwd;
	}
	
	public void setProviderId(String id)
	{
		provider_id = id;
	}
	
	public void setSecurity(String sec)
	{
		security = sec;
	}
	
	public int getData(byte[] buffer, int index)
	{
		int startPos = index;
		
		//<characteristic type="APPLICATION">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x55; //type="APPLICATION"
		buffer[index++] = (byte)0x01;
		//<parm name="APPID" value="25"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x36;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(appid.getBytes(), 0, buffer, index, appid.length());
		index += appid.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm
		
		//<parm name="PROVIDER-ID" value="xxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x38;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
//		System.out.println("SMTP PROVIDER_ID = " + provider_id);
		System.arraycopy(provider_id.getBytes(), 0, buffer, index, provider_id.length());
		index += provider_id.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm
		
		//<parm name="TO-NAPID" value="xxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x22; //name="TO-NAPID"
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(napid.getBytes(), 0, buffer, index, napid.length());
		index += napid.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm
		
		//<parm name="FROM" value="xxxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x05; //name=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy("FROM".getBytes(), 0, buffer, index, 4);
		index += 4;
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(EMAIL_addr.getBytes(), 0, buffer, index, EMAIL_addr.length());
		index += EMAIL_addr.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm
		
		//<characteristic type="APPADDR">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x56; //type="APPADDR"
		buffer[index++] = (byte)0x01;
		//<parm name="ADDR" value="xxxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x34; //name="ADDR"
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(SMTP_addr.getBytes(), 0, buffer, index, SMTP_addr.length());
		index += SMTP_addr.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm	
		
		//<characteristic type="PORT">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x53; //type="PORT"
		buffer[index++] = (byte)0x01;
		
		//<parm name="PORTNBR" value=""/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x23; //name="PORTNBR"
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		/*
		 * if(security.equals("y"))
			SMTP_port = "465";
		*/
		System.arraycopy(SMTP_port.getBytes(), 0, buffer, index, SMTP_port.length());
		index += SMTP_port.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm		
		
		if(security.equals("y")){
		//<parm name="SERVICE" value=""/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x24; //name="SERVICE"
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		//SMTP_port = "TLS";
		System.arraycopy(SMTP_port.getBytes(), 0, buffer, index, SMTP_port.length());
		index += SMTP_port.length();
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm	
		}
		
		buffer[index++] = (byte)0x01; //end of characteristic with the attribute 'PORT'
		buffer[index++] = (byte)0x01; //end of characteristic with the attribute 'APPADDR'
		
		if(SMTP_auth.equals("y")){
		//<characteristic type="APPAUTH">
		buffer[index++] = (byte)0xC6;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x57; //type="APPAUTH"
		buffer[index++] = (byte)0x01;
		
		//<parm name="AAUTHTYPE" value="xxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x33; //name="AAUTHTYPE"
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy("LOGIN".getBytes(), 0, buffer, index, 5);
		index += 5;		
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm		
		
		//<parm name="AAUTHNAME" value="xxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x31; //name="AAUTHNAME"
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(SMTP_id.getBytes(), 0, buffer, index, SMTP_id.length());
		index += SMTP_id.length();		
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm		
		
		//<parm name="AAUTHSECRETE" value="xxx"/>
		buffer[index++] = (byte)0x87;
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x01; //code page 01
		buffer[index++] = (byte)0x32; //name="AAUTHNAME"
		buffer[index++] = (byte)0x00; //switch to 
		buffer[index++] = (byte)0x00; //code page 00
		buffer[index++] = (byte)0x06; //value=
		buffer[index++] = (byte)0x03; //start of inline string
		System.arraycopy(SMTP_pwd.getBytes(), 0, buffer, index, SMTP_pwd.length());
		index += SMTP_pwd.length();		
		buffer[index++] = (byte)0x00; //end of inline string
		buffer[index++] = (byte)0x01; //end of parm			
		buffer[index++] = (byte)0x01; //end of characteristic with the attribute 'APPAUTH'
		}
		
		buffer[index++] = (byte)0x01; //end of characteristic with the attribute 'APPLICATION'
		return index - startPos;
	}

}
